<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    手机号：<input type="text" class="phone">
    <br>
    密码：<input type="paswword" class="userpwd">
    <br>
    <button>登陆</button>


    <script src="../js/tools.js"></script>
    <script>


        // 1 获取输入的用户名和密码
        // 2 去'数据库中'查找这个用户名是否存在
        //    找到了用户名    --  判断密码是否正确
        //    找不到

        const oPhone = get('.phone') ;
        const oPwd = get('.userpwd') ;
        const oBtn = get('button') ;

        oBtn.addEventListener('click' , function(){
            const phone = oPhone.value.trim() ;
            const password = oPwd.value.trim() ;

            // 判断手机号是否存在
            const res = localStorage.getItem(phone) ;
            console.log(res);
            
            if(res) {
                //  判断密码
                const o = JSON.parse(res);
                if(password === o.password) {
                    // 记住登陆状态
                    localStorage.setItem('USER_LOGIN' , phone);
                    // alert('ok');
                    location.href = './10_user.html';
                } else {
                    alert('密码错误')
                }
            } else {
                alert('手机号不存在');
            }

        })


    </script>
    
</body>
</html>